<?php
// Allow for asynchronous interaction with this file
// by including the MODx index file for access to the
// DocumentParser object.
if (!defined('MODX_BASE_PATH'))
{
    define('MODX_BASE_PATH', dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/' );
    define('MODX_API_MODE', true);
    define('MXW_BASE', MODX_BASE_PATH . 'assets/modules/mxw/');
    require_once MODX_BASE_PATH . 'index.php';
}

// Include the helper files
include_once(MXW_BASE.'control/mxw.setup.helper.php');
include_once(MXW_BASE.'control/mxw.view.helper.php');

mxwSetup::setup();
$lexicon = mxwSetup::getLexicon();
include_once($lexicon->manager);
include_once($lexicon->mxw);
$lexicon = (object) $_lang;

// echo mxwView::json('overview');
switch ($_POST['action'])
{
    case 'new_product':
        echo mxwView::json('new_product');
        return;
        break;
        
    case 'edit_product':
        echo mxwView::json('edit_product');
        return;
        break;
        
    case 'lexicon':
        echo json_encode($lexicon);
        return;
        break;
        
    case 'overview':
        echo mxwView::json('overview');
        return;
        break;
    
    default:
        $theme = $modx->config['manager_theme'];
        $css = '/manager/media/style/'.$theme.'/style.css';
        $view = file_get_contents(MXW_BASE.'view/index.html');
        $view = str_replace('[+mxw.manager_theme+]', $css, $view);
        $view = str_replace('[+mxw_name+]', $_lang['mxw_name'], $view);
        $view = str_replace('[+site_name+]', $modx->config['site_name'], $view);
        echo $view;
        break;
}